toast('Hello, AutoX.js');


/**
 * @description launcher
 */

try {
    auto.waitFor();
} catch (e) {
    auto();
}


// 导入其他脚本文件
// var network = require('network.js');
// var ui = require('ui.js');
var f = require('f.js');


f.init()



var appinfo = {}
appinfo.bid = 'cn.xuexi.android'
appinfo.read_state = f.getLocal('read_state') || 'see'
appinfo.read_times = 0
appinfo.read_title_id = f.getLocal('read_title_id') || []
console.log('已经读过的内容', appinfo.read_title_id)
appinfo.read_see_time = 0
appinfo.device = device

appinfo.video_state = f.getLocal('video_state') || 'see'
appinfo.video_times = 0
appinfo.video_title_id = f.getLocal('video_title_id') || []
console.log('已经观看过的视频', appinfo.video_title_id)
appinfo.video_see_time = 0

console.log('appinfo', appinfo)

appinfo.comment_status = f.getLocal('comment_status') || 'todo'

recents()
sleep(3000)
f.ms({"id":'clearbox'}, true, 2)

// 使用其他脚本中的函数
// network.sendRequest();
// ui.showDialog();
// ui.init();

var read = require('read.js');
var video = require('video.js');
var commmnet = require('commnet.js');

function son(obj, click_key){
    let r = []
    var children = obj.children();
    for (var i = 0; i < children.length; i++) {
        var child = children[i];
        // log(child.text());
        if (child.text() ){
            r.push(child.text())
            if (click_key && child.text() == '去看看'){
                child.click()
            }
        }
        if (child.children().length > 0 ){
            r.push(son(child))
        }
    }
    return r
}


function isday(){
    var today = f.getCurrentDate()
    console.log('today', today)
    if ( today != f.getLocal('today')  ){
        f.setLocal('today', today)
        appinfo.read_state = 'see'
        appinfo.video_state = 'see'
        appinfo.read_title_id = []
        appinfo.video_title_id = []
        appinfo.comment_status = true
        f.setLocal('comment_status', true)
        f.setLocal('read_state', 'see')
        f.setLocal('video_state', 'see')
        f.setLocal('read_title_id', [])
        f.setLocal('video_title_id', [])
    }
}



// exit()

while (true){
    isday()
    
    f.active(appinfo.bid, 10); //启动app

    if( f.ms({"text":"访问异常"}) ){
        f.notice("出现异常")
        exit()
    }

    if( appinfo.comment_status == 'todo' ){
        commmnet.commnet()
    }

    if (appinfo.read_state ){
        console.log('appinfo.read_state', appinfo.read_state)
        read.read()
    }else
    if (appinfo.video_state ){
        console.log('appinfo.video_state', appinfo.video_state)
        video.read()
    }else{

        f.notice('学习结束')
        alert("学习结束");
        exit()
    }
    
    sleep(3000)
}




// f.ms({"text":"第一频道"})





// 主脚本的其他逻辑代码
// ...

toast("end")


